const express = require("express");
const cors = require("cors");
const path = require("path");

const corsOptions = {
  origin: "http://localhost:3000",
  methods: ["GET", "HEAD", "OPTION", "POST", "PUT", "DELETE", "PATCH"],
};

const bodyParser = require("body-parser");
// const morgan = require("morgan");

const app = express();

// 配置静态资源目录 整一个文件夹 通过域名能访问
app.use("/exceldata", express.static(path.join(__dirname, "exceldata")));

//1.MIDLEWARE
app.use(express.json());
app.use(cors(corsOptions));
app.use(bodyParser.json());

//2.ROUTE
const userRoutes = require("./routes/userRoutes");
const interviewRoutes = require("./routes/interviewRoutes");
const interviewSpeedRoutes = require("./routes/interviewSpeedRoutes");

const quesRoutes = require("./routes/quesRoutes");
const problemRoutes = require("./routes/problemRoutes");
const userQuesRoutes = require("./routes/userQuesRoutes");
const userProRoutes = require("./routes/useProRoutes");
const opinionRoutes = require("./routes/opinionRoutes");
const quesSpeedRoutes = require("./routes/quesSpeedRoutes");
const fileDataRoutes = require("./routes/fileDataRoutes");

const articleRoutes = require("./routes/articleRoutes");
const testQuesRoutes = require("./routes/testQuesRoutes");
const testRoutes = require("./routes/testRoutes");
const scoreRoutes = require("./routes/scoreRoutes");
const sampleVillageRoutes = require("./routes/sampleVillageRoutes");
const reportRoutes = require("./routes/reportRoutes");
const locationRoutes = require("./routes/locationRoutes");
const excelRoutes = require("./routes/excelRoutes");

app.use("/user", userRoutes);
app.use("/interview", interviewRoutes);
app.use("/interviewspeed", interviewSpeedRoutes);

app.use("/ques", quesRoutes);
app.use("/problem", problemRoutes);
app.use("/userques", userQuesRoutes);
app.use("/userproblem", userProRoutes);
app.use("/opinion", opinionRoutes);
app.use("/quesspeed", quesSpeedRoutes);
app.use("/filedata", fileDataRoutes);

app.use("/article", articleRoutes);
app.use("/testQues", testQuesRoutes);
app.use("/test", testRoutes);
app.use("/score", scoreRoutes);
app.use("/sampleVillage", sampleVillageRoutes);
app.use("/report", reportRoutes);
app.use("/location", locationRoutes);
app.use("/excel", excelRoutes);

module.exports = app;
